let currentCourse = []

let getStudentByTeacher = async (userid,coursetime,state = '1') => {
    let res = await ajax('order_query',{
        userid : parseInt(userid),
        coursetime,
        state
    },'post')
    res?.data.forEach(item => {
        let year = item.cuyaer
        let month = item.cumonth 
        let date = item.cuday
        let time = item.timequantum
        item.timestamp = new Date(`${year}-${month}-${date} ${time}`).getTime()
    })
    return res?.data
}

let buy = (list,list2) => {
    if(list2.length) currentCourse = list2
    let body = document.createElement('div')
    body.className = 'buy'
    let section = document.createElement('section')
    section.className = 'faq'
    let section_list = `
        <div class="list">
            <i class="iconfont icon-xuexishuben" style='color:#DADFE1'></i>
            <div style='margin-left:13px'>
                <span style="color: #3C3C3C;">科目</span>
                <span style="color: #92979B;margin-top: 7px;">${list.dialect}</span>
            </div>
        </div>
    `
    let section_list2 = `
        <div class="list">
            <i class="iconfont icon-diqiu" style='color:#DADFE1'></i>
            <div style='margin-left:13px'>
                <span style="color: #3C3C3C;">老师的时间</span>
                <span style="color: #92979B;margin-top: 7px;">${list.zone}</span>
            </div>
        </div>
    `
    let section_list3 = `
        <div class="list">
            <i class="iconfont icon-wodekecheng" style='color:#DADFE1'></i>
            <div style='margin-left:13px'>
                <span style="color: #3C3C3C;">已购买的课时</span>
                <span style="color: #92979B;margin-top: 7px;">1课时</span>
            </div>
        </div>
    `
    let section_list4 = `
        <div class="list">
            <i class="iconfont icon-bangzhu" style='color:#DADFE1'></i>
            <div style='margin-left:13px' >
                <span style="color: #3C3C3C;">详细资料</span>
                <span style="color: #92979B;margin-top: 7px;">学习目标：<span style="color: #3C3C3C;">${list.learningobjectives}</span></span>
                <span style="color: #92979B;">每周课时数：<span style="color: #3C3C3C;">${list.weeklycurriculum}</span></span>
            </div>
        </div>
    `
    section.innerHTML = section_list + section_list2 + section_list3 + section_list4
    let btn = document.createElement('div')
    btn.className = 'third-bottom-btn'
    let btn1 = `
        <div class='order-class'>
            预定课程
        </div>
    `
    let btn2 = `
        <div class='entry-course'>
            进入教室
        </div>
    `
    let btn3 = `
        <div class='dialog-open-star' >
            评价
        </div>
    `
    btn.innerHTML = btn1 + btn2 + btn3
    body.appendChild(section)
    body.appendChild(btn)

    

    return body
}

let listenerEntryCourse = () => {
    $('.entry-course')[0].addEventListener('click',() => {
        let current_date = new Date().getTime()
        let is_current_up_course = false
        currentCourse.forEach(item => {
            let year = new Date().getFullYear() + ''
            let month = new Date().getMonth() + 1 + ''
            let date = new Date().getDate() + ''
            let now = new Date(year + '/' + month + '/' + date + ' ' + item.timequantum).getTime()
            if(current_date > now){
                if(current_date < now + (1000 * 60 * 60 )){
                    is_current_up_course = true
                    window.location.href = `/views/attendClass/student/classHistory.html?teacherid=${item.userid}&curriculumid=${item.id}&state=0`
                }
            }
        })
        if(!is_current_up_course){
            Dreamer.error('未到上课时间！')
        }
        console.log(currentCourse)
    })
}

let nobuy = () => {
    let body = document.createElement('div')
    let top = document.createElement('div')
    let bottom = document.createElement('div')
    bottom.className = 'third-bottom-btn'
    top.className = 'third-bottom-wrap'
    let list1 = `
        <div class="wrap-list">
            <span class="list-circle">1</span>
            <div style="font-size:12px;flex: 1;">
                <div style="color:#3C3C3C">选择时间</div>
                <div style="color: #92979B;margin-top: 6px;">就您的第一节课选择适合的日期和时间</div>
            </div>
            <div></div>
        </div>
    `
    let list2 = `
        <div class="wrap-list">
            <span class="list-circle">2</span>
            <div style="font-size:12px;flex: 1;">
                <div style="color:#3C3C3C">付款</div>
                <div style="color: #92979B;margin-top: 6px;">通过信用卡或者支付宝，进行安全的网上付款</div>
                <div style="margin-top: 8px;">
                    <svg style="width: 24px;height:16px;" aria-hidden="true">
                        <use xlink:href="#icon-a-Icon_Payment_Visa"></use>
                    </svg>
                    <svg style="width: 24px;height:16px;" aria-hidden="true">
                        <use xlink:href="#icon-mastercard"></use>
                    </svg>
                    <svg style="width: 24px;height:16px;" aria-hidden="true">
                        <use xlink:href="#icon-amex"></use>
                    </svg>
                    <svg style="width: 24px;height:16px;" aria-hidden="true">
                        <use xlink:href="#icon-jcb1"></use>
                    </svg>
                    <svg style="width: 24px;height:16px;" aria-hidden="true">
                        <use xlink:href="#icon-discover1"></use>
                    </svg>
                    <svg style="width: 24px;height:16px;" aria-hidden="true">
                        <use xlink:href="#icon-zhifu-zhifubao"></use>
                    </svg>
                </div>
            </div>
            <div></div>
        </div> 
    `
    let list3 = `
        <div class="wrap-list">
            <span class="list-circle">3</span>
            <div style="font-size:12px;flex: 1;">
                <div style="color:#3C3C3C">在CLO教室中上课</div>
                <div style="color: #92979B;margin-top: 6px;">和您的老师在我们的虚拟教室中进行视频学习</div>
            </div>
            <div></div>
        </div>
    `
    top.innerHTML = list1 + list2 + list3
    let bottom1 = `
        <div class='order-class'>
            预定课程
        </div>
    `
    bottom.innerHTML = bottom1
    body.appendChild(top)
    body.appendChild(bottom)
    return body
}

export {
    listenerEntryCourse,
    getStudentByTeacher,
    buy,
    nobuy
}